package work.mediway.mdm.biz.vo.dict;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2020/12/17
 */
@Data
@ApiModel("字典返回实体")
public class DictVO implements RowMapper<DictVO> {

    @ApiModelProperty(value = "字典业务域")
    private String businessFieldCode;

    @ApiModelProperty(value = "字典业务域内唯一编号")
    private String businessRowId;

    @ApiModelProperty(value = "字典Code")
    private String code;

    @ApiModelProperty(value = "字典Desc")
    private String descr;

    @ApiModelProperty(value = "主键字段")
    private String primaryKey;

    @ApiModelProperty(value = "主键字段值")
    private String primaryKeyVal;

    /**
     * 保留字段，暂时未使用
     */
    @ApiModelProperty(value = "字典状态", hidden = true)
    private String status;

    public DictVO() {
    }

    public DictVO(String businessFieldCode, String businessRowId, String code, String descr, String status) {
        this.businessFieldCode = businessFieldCode;
        this.businessRowId = businessRowId;
        this.code = code;
        this.descr = descr;
        this.status = status;
    }

    @Override
    public DictVO mapRow(ResultSet resultSet, int rowNum) throws SQLException {
        DictVO dictVO = new DictVO();
        dictVO.setBusinessFieldCode(resultSet.getString("businessFieldCode"));
        dictVO.setBusinessRowId(resultSet.getString("businessrowid"));
        dictVO.setCode(resultSet.getString("code"));
        dictVO.setDescr(resultSet.getString("descr"));
        dictVO.setStatus(resultSet.getString("status"));
        dictVO.setPrimaryKey(resultSet.getString("primaryKey"));
        dictVO.setPrimaryKeyVal(resultSet.getString(dictVO.getPrimaryKey()));
        return dictVO;
    }
}
